package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	s := "Yes我爱慕课网!" // UTF-8
	fmt.Println(s)

	for _, b := range []byte(s) {
		fmt.Printf("%X ", b) // 每个中文三个字节，输出二进制码
	}
	fmt.Println()

	for i, ch := range s { // ch is a rune
		fmt.Printf("(%d %X) ", i, ch) // ch是union code
	}
	fmt.Println()

	fmt.Println("Rune count:", utf8.RuneCountInString(s))

	bytes := []byte(s) // []byte获取字节
	for len(bytes) > 0 {
		ch, size := utf8.DecodeRune(bytes)
		bytes = bytes[size:]
		fmt.Printf("%c ", ch) // 输出每个字符 Y e s 我 爱 慕 课 网 !
	}
	fmt.Println()

	for i, ch := range []rune(s) { // rune 相当于go的char
		fmt.Printf("(%d %c) ", i, ch)
	}
	fmt.Println()

	/**
	Fields, Split, Join
	Contains, Index
	ToLower, ToUpper
	Trim, TrimRight, TrimLeft
	 */
}
